package com.hua.designpattern.behavioral.observer;

import java.util.ArrayList;
import java.util.List;

public class ObserverSubject {

	private String message;

	List<ObserverInterface> observers = new ArrayList<ObserverInterface>();

	public void addObserver(ObserverInterface observer) {
		observers.add(observer);
	}

	public void removeObserver(ObserverInterface observer) {
		observers.remove(observer);
	}

	public void notityAllObserver() {
		for (ObserverInterface observer : observers) {
			observer.update(message);
		}
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
		notityAllObserver();
	}

}
